<?php

class ValuationsController extends CFD_Controller_Action
{
    public function init()
	{
	  parent::init();
	  $this->isAdmin(true);
	}

    public function entryAction()
	{
		$this->view->translate = new Zend_Translate(
	      array (
		          'adapter' => 'array',
				  'content' => LANGUAGES_PATH.DIRECTORY_SEPARATOR.LANGUAGE.'/valuations.php',
				  'locale'  => 'de'
			    )
		);

        $valTable = new Application_Model_CarValuations();
		$this->view->valRow = $valRow = $valTable->fetchRow($valTable->select()->where('id = ?', (int)$_GET['id']) );

		if (!$valRow)
	      Alert_View::addMessage(Alert_View::WARNING, "", "This record doesn't exist.");
		  
	}

    public function browseAction()
    {
        $valTable = new Application_Model_CarValuations();
		$adapter = new Zend_Paginator_Adapter_DbSelect($valTable->select()->order('id DESC'));

		$res = $valTable->getAdapter()->query("SELECT COUNT(*) as count FROM car_valuations");
		$count = $res->fetchAll();
		$count = $count[0]['count'];

		$adapter->setRowCount( (int)$count );

		$paginator = $this->view->paginator = new Zend_Paginator($adapter);
		$paginator->setItemCountPerPage(10);
		$paginator->setCurrentPageNumber($this->_request->getParam('page'));

		$wlTable = new Application_Model_WhiteLabels();
		$this->veiw->wlList = $wlList = $wlTable->fetchAll();
		$wlListAr = array();

		foreach ($wlList as $wlRow)
		  $wlListAr[ $wlRow->id ] = $wlRow;

		$this->view->wlListAr = $wlListAr;
    }
}
